package com.hsc.yalebao.base;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hsc.pcddfivepcdd.R;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.http.RequestNet;
import com.hsc.yalebao.model.BaseDataObject;
import com.hsc.yalebao.model.UserBaseBean;
import com.hsc.yalebao.model.UserBean;
import com.hsc.yalebao.tabIndex.CustomServiceActivity;
import com.hsc.yalebao.tabMine.ForgetLoginPwdActivity;
import com.hsc.yalebao.tools.SharedPreferencesUtil;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;

import okhttp3.Call;

public class LoginActivity extends BaseActivity
        implements View.OnClickListener {
    private String TAG = "LoginActivity";
    private View contentView;
    private Context context;
    public EditText edit_login_psw;
    public EditText edit_login_username;
    private EditText edit_register_introduce;
    private EditText edit_register_nickname;
    private EditText edit_register_psw;
    private EditText edit_register_rppsw;
    private EditText edit_register_username;
    private ImageView img_login;
    private ImageView img_register;
    private ImageView iv_login;
    private ImageView iv_register;
    private String registerIntroduceId = "";
    private String registerNickName = "";
    private String registerUserName = "";
    private String registerUserPsw = "";
    private String registerUserPswRp = "";
    private Resources resources;
    private ScrollView scroll_register;
    private TextWatcher textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable paramAnonymousEditable) {
        }

        public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
        }

        public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            if ("".equals(LoginActivity.this.edit_login_username.getText().toString()))
                LoginActivity.this.edit_login_psw.setText("");
        }
    };
    private TextView tv_forget_pwd;
    private TextView tv_lianxi_kefu;
    private TextView tv_user_con_psw_tishi;
    private TextView tv_user_name_tishi;
    private TextView tv_user_nick_name_tishi;
    private TextView tv_user_psw_tishi;
    private String userName = "";
    private String userPsw = "";
    View viewLogin;
    View viewRegister;
    public PopupWindow window_login;
    public PopupWindow window_register;

    private void goLogin() {
        this.userName = this.edit_login_username.getText().toString();
        this.userPsw = this.edit_login_psw.getText().toString();
        if ("".equals(this.userName)) {
            UiUtil.showToast(this.context, "请输入您的账号");
            this.edit_login_username.requestFocus();
            return;
        }
        if ("".equals(this.userPsw)) {
            UiUtil.showToast(this.context, "请输入您的密码");
            this.edit_login_username.requestFocus();
            return;
        }
        HashMap localHashMap = new HashMap();
        localHashMap.put("user_name", this.userName);
        localHashMap.put("password", this.userPsw);
        localHashMap.put("client_type", "1");
        localHashMap.put("client_Id", CustomApplication.app.IMEI);
        localHashMap.put("Client_Ip", CustomApplication.app.NetIP);
        LogUtils.d(this.TAG, "userName:" + this.userName);
        LogUtils.d(this.TAG, "userPsw:" + this.userPsw);
        setLoginBtnIsEnable(false);
        RequestNet.post(this.context, AppConstants.URL_LOGIN, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                LogUtils.e(LoginActivity.this.TAG, "登陆失败,login-result:" + paramAnonymousException);
                LoginActivity.this.setLoginBtnIsEnable(true);
            }

            public void onResponse(String paramAnonymousString) {
                LoginActivity.this.setLoginBtnIsEnable(true);
                if (paramAnonymousString.isEmpty())
                    LogUtils.e(LoginActivity.this.TAG, "AppConstants.URL_LOGIN s.isEmpty()");
                do {
                    return;
                    Gson localGson = new Gson();
                    try {
                        localUserBean = (UserBean) localGson.fromJson(paramAnonymousString, UserBean.class);
                        if (localUserBean == null) {
                            UiUtil.showToast(LoginActivity.this.context, "登陆失败");
                            return;
                        }
                    } catch (Exception localException) {
                        UserBean localUserBean;
                        while (true) {
                            localException.printStackTrace();
                            localUserBean = null;
                        }
                        LogUtils.e(LoginActivity.this.TAG, "s:  " + paramAnonymousString);
                        CustomApplication.app.userBaseBean = localUserBean.getResult();
                        if (localUserBean.getFlag() != 1) {
                            LoginActivity.this.ShowDialog1(localUserBean.getMsg());
                            return;
                        }
                    }
                }
                while (CustomApplication.app.userBaseBean == null);
                LogUtils.i(LoginActivity.this.TAG, "登陆成功");
                CustomApplication.app.isLogin = true;
                String str1 = CustomApplication.app.userBaseBean.getGuid();
                String str2 = CustomApplication.app.userBaseBean.getAccessToken();
                LogUtils.d(LoginActivity.this.TAG, "guid：" + str1);
                LogUtils.d(LoginActivity.this.TAG, "accessToken：" + str2);
                LogUtils.d(LoginActivity.this.TAG, "memberId：" + CustomApplication.app.userBaseBean.getMemberid());
                LogUtils.d(LoginActivity.this.TAG, "SessionToken：" + CustomApplication.app.userBaseBean.getSessionToken());
                if (LoginActivity.this.window_login != null)
                    LoginActivity.this.window_login.dismiss();
                CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_TOKEN, str2);
                CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_USERNAME, LoginActivity.this.userName);
                CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_PWD, LoginActivity.this.userPsw);
                CustomApplication.app.finishActivity(LoginActivity.this);
            }
        });
    }

    private void goRegister() {
        this.registerUserName = this.edit_register_username.getText().toString();
        this.registerUserPsw = this.edit_register_psw.getText().toString();
        this.registerUserPswRp = this.edit_register_rppsw.getText().toString();
        this.registerNickName = this.edit_register_nickname.getText().toString();
        this.registerIntroduceId = this.edit_register_introduce.getText().toString();
        if ("".equals(this.registerUserName)) {
            this.tv_user_name_tishi.setText("请输入您的账号");
            this.edit_register_username.requestFocus();
            this.scroll_register.fullScroll(33);
            return;
        }
        if (!UiUtil.isValidUserName(this.registerUserName)) {
            this.tv_user_name_tishi.setText("6~12位字母或数字");
            this.edit_register_username.requestFocus();
            return;
        }
        if ("".equals(this.registerUserPsw)) {
            this.tv_user_psw_tishi.setText("请输入您的密码");
            this.edit_register_psw.requestFocus();
            return;
        }
        if (this.registerUserName.equals(this.registerUserPsw)) {
            this.tv_user_psw_tishi.setText("账号和密码不能一致");
            this.edit_register_psw.requestFocus();
            return;
        }
        if (!this.registerUserPsw.equals(this.registerUserPswRp)) {
            this.tv_user_con_psw_tishi.setText("两次密码不一致");
            this.edit_register_rppsw.requestFocus();
            return;
        }
        if ("".equals(this.registerIntroduceId))
            this.registerIntroduceId = "0";
        if ("".equals(this.registerNickName)) {
            this.tv_user_nick_name_tishi.setText("请输入您的昵称");
            this.edit_register_nickname.requestFocus();
            return;
        }
        if (!UiUtil.isContainsChinese(this.registerNickName)) {
            this.tv_user_nick_name_tishi.setText("昵称需要包含中文");
            this.edit_register_nickname.requestFocus();
            return;
        }
        this.tv_user_name_tishi.setText("");
        this.tv_user_psw_tishi.setText("");
        this.tv_user_con_psw_tishi.setText("");
        this.tv_user_nick_name_tishi.setText("");
        HashMap localHashMap = new HashMap();
        localHashMap.put("nick_name", this.registerNickName);
        localHashMap.put("user_name", this.registerUserName);
        localHashMap.put("password", this.registerUserPsw);
        localHashMap.put("pid", this.registerIntroduceId);
        setRegisterBtnIsEnable(false);
        RequestNet.get(this.context, AppConstants.URL_REGISTER, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                LogUtils.e("注册失败", "register-result:" + paramAnonymousException);
                LoginActivity.this.setRegisterBtnIsEnable(true);
            }

            public void onResponse(String paramAnonymousString) {
                LoginActivity.this.setRegisterBtnIsEnable(true);
                if (paramAnonymousString.isEmpty()) ;
                while (true) {
                    return;
                    Gson localGson = new Gson();
                    try {
                        localBaseDataObject = (BaseDataObject) localGson.fromJson(paramAnonymousString, BaseDataObject.class);
                        if (localBaseDataObject != null)
                            if (localBaseDataObject.getFlag() != 1) {
                                LoginActivity.this.ShowDialog1(localBaseDataObject.getMsg());
                                return;
                            }
                    } catch (Exception localException) {
                        while (true) {
                            localException.printStackTrace();
                            BaseDataObject localBaseDataObject = null;
                        }
                        LogUtils.d("注册成功", "register-result:" + paramAnonymousString);
                        UiUtil.showToast(LoginActivity.this.context, "注册成功");
                        LoginActivity.this.window_register.dismiss();
                        LoginActivity.this.userName = LoginActivity.this.registerUserName;
                        LoginActivity.this.userPsw = LoginActivity.this.registerUserPsw;
                        CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_USERNAME, LoginActivity.this.registerUserName);
                        CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_PWD, LoginActivity.this.registerUserPsw);
                        LoginActivity.this.closeWindowSoftInput(LoginActivity.this.getCurrentFocus());
                        LoginActivity.this.edit_login_username.setText(LoginActivity.this.registerUserName);
                        LoginActivity.this.edit_login_psw.setText(LoginActivity.this.registerUserPsw);
                        LoginActivity.this.goLogin();
                    }
                }
            }
        });
    }

    private void setLoginBtnIsEnable(boolean paramBoolean) {
        if (paramBoolean)
            this.img_login.setBackgroundResource(2130837557);
        while (true) {
            this.img_login.setEnabled(paramBoolean);
            return;
            this.img_login.setBackgroundResource(2130837754);
        }
    }

    private void setRegisterBtnIsEnable(boolean paramBoolean) {
        if (paramBoolean)
            this.img_register.setBackgroundResource(2130837572);
        while (true) {
            this.img_register.setEnabled(paramBoolean);
            return;
            this.img_register.setBackgroundResource(2130838119);
        }
    }

    private void showLoginPopwindow() {
        (9 * (10 * (CustomApplication.app.displayMetrics.widthPixels / 10) / 10));
        this.window_login = new PopupWindow(this.viewLogin, -1, -1);
        this.window_login.setFocusable(true);
        ImageView localImageView = (ImageView) this.viewLogin.findViewById(2131100198);
        localImageView.bringToFront();
        localImageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                LoginActivity.this.window_login.dismiss();
            }
        });
        this.userName = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, this.userName);
        this.userPsw = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_PWD, this.userPsw);
        if (!"".equals(this.userName))
            this.edit_login_username.setText(this.userName);
        if (!"".equals(this.userPsw))
            this.edit_login_psw.setText(this.userPsw);
        this.window_login.setSoftInputMode(16);
        this.img_login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                LoginActivity.this.closeWindowSoftInput(LoginActivity.this.getCurrentFocus());
                LoginActivity.this.goLogin();
            }
        });
        this.window_login.setBackgroundDrawable(this.context.getResources().getDrawable(2130837534));
        this.window_login.setAnimationStyle(2131361795);
        this.window_login.showAtLocation(this.contentView, 17, 0, 60);
        this.window_login.setOnDismissListener(new PopupWindow.OnDismissListener() {
            public void onDismiss() {
                LoginActivity.this.iv_login.setVisibility(0);
                LoginActivity.this.iv_register.setVisibility(0);
            }
        });
    }

    private void showRegisterPopwindow() {
        this.scroll_register = ((ScrollView) this.viewRegister.findViewById(2131100190));
        (4 * CustomApplication.app.displayMetrics.widthPixels / 3);
        this.window_register = new PopupWindow(this.viewRegister, -1, -1);
        this.window_register.setFocusable(true);
        ImageView localImageView = (ImageView) this.viewRegister.findViewById(2131100198);
        localImageView.bringToFront();
        localImageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                LoginActivity.this.window_register.dismiss();
            }
        });
        this.tv_user_name_tishi = ((TextView) this.viewRegister.findViewById(2131100199));
        this.tv_user_psw_tishi = ((TextView) this.viewRegister.findViewById(2131100201));
        this.tv_user_con_psw_tishi = ((TextView) this.viewRegister.findViewById(2131100203));
        this.tv_user_nick_name_tishi = ((TextView) this.viewRegister.findViewById(2131100207));
        this.tv_lianxi_kefu = ((TextView) this.viewRegister.findViewById(2131100211));
        this.tv_lianxi_kefu.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                LoginActivity.this.startActivity(new Intent(LoginActivity.this, CustomServiceActivity.class));
            }
        });
        this.edit_register_username = ((EditText) this.viewRegister.findViewById(2131100200));
        this.edit_register_username.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean) {
                LoginActivity.this.registerUserName = LoginActivity.this.edit_register_username.getText().toString();
                if (!LoginActivity.this.edit_register_username.hasFocus()) {
                    if ("".equals(LoginActivity.this.registerUserName))
                        LoginActivity.this.tv_user_name_tishi.setText("请输入您的账号");
                } else
                    return;
                if (!UiUtil.isValidUserName(LoginActivity.this.registerUserName)) {
                    LoginActivity.this.tv_user_name_tishi.setText("账号需要6~12位字符或数字");
                    return;
                }
                LoginActivity.this.tv_user_name_tishi.setText("");
            }
        });
        this.edit_register_psw = ((EditText) this.viewRegister.findViewById(2131100202));
        this.edit_register_psw.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean) {
                LoginActivity.this.registerUserPsw = LoginActivity.this.edit_register_psw.getText().toString();
                if (!LoginActivity.this.edit_register_psw.hasFocus()) {
                    if ("".equals(LoginActivity.this.registerUserPsw))
                        LoginActivity.this.tv_user_psw_tishi.setText("请输入您的密码");
                } else
                    return;
                if (!UiUtil.isValidUserName(LoginActivity.this.registerUserPsw)) {
                    LoginActivity.this.tv_user_psw_tishi.setText("密码需要6~12位字符或数字");
                    return;
                }
                if (LoginActivity.this.registerUserName.equals(LoginActivity.this.registerUserPsw)) {
                    LoginActivity.this.tv_user_psw_tishi.setText("账号和密码不能一致");
                    return;
                }
                LoginActivity.this.tv_user_psw_tishi.setText("");
            }
        });
        this.edit_register_rppsw = ((EditText) this.viewRegister.findViewById(2131100204));
        this.edit_register_rppsw.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean) {
                LoginActivity.this.registerUserPswRp = LoginActivity.this.edit_register_rppsw.getText().toString();
                if (!LoginActivity.this.edit_register_rppsw.hasFocus()) {
                    if (!LoginActivity.this.registerUserPsw.equals(LoginActivity.this.registerUserPswRp))
                        LoginActivity.this.tv_user_con_psw_tishi.setText("两次密码不一致");
                } else
                    return;
                LoginActivity.this.tv_user_con_psw_tishi.setText("");
            }
        });
        this.edit_register_introduce = ((EditText) this.viewRegister.findViewById(2131100206));
        this.edit_register_nickname = ((EditText) this.viewRegister.findViewById(2131100208));
        this.edit_register_nickname.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean) {
                LoginActivity.this.registerNickName = LoginActivity.this.edit_register_nickname.getText().toString();
                LogUtils.e(LoginActivity.this.TAG, "registerNickName：" + LoginActivity.this.registerNickName);
                if (!LoginActivity.this.edit_register_nickname.hasFocus()) {
                    if ("".equals(LoginActivity.this.registerNickName))
                        LoginActivity.this.tv_user_nick_name_tishi.setText("请输入您的昵称");
                } else
                    return;
                if (!UiUtil.isContainsChinese(LoginActivity.this.registerNickName)) {
                    LoginActivity.this.tv_user_nick_name_tishi.setText("昵称需要包含中文");
                    return;
                }
                LoginActivity.this.tv_user_nick_name_tishi.setText("");
            }
        });
        this.window_register.setSoftInputMode(16);
        this.img_register.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                LoginActivity.this.closeWindowSoftInput(LoginActivity.this.getCurrentFocus());
                LoginActivity.this.goRegister();
            }
        });
        this.window_register.setBackgroundDrawable(this.context.getResources().getDrawable(2130837534));
        this.window_register.setAnimationStyle(2131361795);
        this.window_register.showAtLocation(this.contentView, 17, 0, 60);
        this.window_register.setOnDismissListener(new PopupWindow.OnDismissListener() {
            public void onDismiss() {
                LoginActivity.this.iv_login.setVisibility(0);
                LoginActivity.this.iv_register.setVisibility(0);
            }
        });
    }

    public boolean dispatchKeyEvent(KeyEvent paramKeyEvent) {
        if ((paramKeyEvent.getKeyCode() == 4) && (paramKeyEvent.getAction() == 0))
            return false;
        return super.dispatchKeyEvent(paramKeyEvent);
    }

    public void onClick(View paramView) {
        switch (paramView.getId()) {
            default:
            case R.id.iv_login:
            case R.id.iv_register:
            case R.id.tv_forget_pwd:
        }
        while (true) {
            this.iv_login.setVisibility(8);
            this.iv_register.setVisibility(8);
            return;
            showLoginPopwindow();
            continue;
            showRegisterPopwindow();
            continue;
            startActivity(new Intent(this, ForgetLoginPwdActivity.class));
        }
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        requestWindowFeature(1);
        getWindow().setFlags(1024, 256);
        setRequestedOrientation(1);
        this.context = this;

        this.contentView = LayoutInflater.from(this.context).inflate(R.layout.activity_login, null);
        setContentView(this.contentView);
        CustomApplication.app.addActivity(this);
        this.iv_login = ((ImageView) this.contentView.findViewById(R.id.iv_login));
        this.iv_register = ((ImageView) this.contentView.findViewById(R.id.iv_register));
        this.iv_login.setOnClickListener(this);
        this.iv_register.setOnClickListener(this);
        this.resources = this.context.getResources();
        this.viewLogin = LayoutInflater.from(this.context).inflate(R.layout.layout_pop_login, null);
        this.tv_forget_pwd = ((TextView) this.viewLogin.findViewById(R.id.tv_forget_pwd));
        this.tv_forget_pwd.setOnClickListener(this);
        this.img_login = ((ImageView) this.viewLogin.findViewById(R.id.img_login));
        this.edit_login_username = ((EditText) this.viewLogin.findViewById(R.id.edit_login_username));
        this.edit_login_username.addTextChangedListener(this.textWatcher);
        this.edit_login_psw = ((EditText) this.viewLogin.findViewById(R.id.edit_login_psw));
        this.viewRegister = LayoutInflater.from(this.context).inflate(R.layout.layout_pop_register, null);
        this.img_register = ((ImageView) this.viewRegister.findViewById(R.id.img_register));
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.base.LoginActivity
 * JD-Core Version:    0.6.2
 */